package com.atqh.srrt.chicken.controller.QAController;

import com.atqh.srrt.chicken.domain.Project;
import com.atqh.srrt.chicken.repository.ProjectRepository;
import com.atqh.srrt.chicken.utils.Result;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/project")
public class ProjectController {
    @Resource
    private ProjectRepository projectRepository;

    @GetMapping("/list")
    public Result list() {
        List<Project> projects = projectRepository.findAll();
        return Result.success(projects);
    }

    @GetMapping("/getByProject")
    public Result getByProject(
            @RequestParam("projectId") String projectId
    ) {
        Project project = projectRepository.findById(projectId).get();
        return Result.success(project);
    }

    @PostMapping("/add")
    public Result addAnalyse(@RequestBody Project[] projects) {
        projectRepository.saveAll(Arrays.asList(projects));
        return Result.success(true);
    }
}
